Dragos Ailoae

2021-09-19

Introduction to R

The Basics

Let's start by loading some data:

To view the data, we can use the environment viewer in RStudio or any of the following:

To extract a variable from the data frame (the x variable for example):

To assign to a new variable:

For basic statistics:

To apply the same function to each vector in the dataframe:

The 'apply' functions are a very useful feature of R (a good explanation here):

Or use prepackaged functions:

Note that we have access to the output of a function just like any other object. So we can extract just the output we need:

Basic plot:

For details on the "datasaurus" dataset and why it is important to visualize our data see here

DinoSequentialSmaller.gif